Posted by Emil on 12/14/92 11:49
paul@sunnyland.com.au napisał(a):
> Hi could anyone please help me. I am a newbie to php. I am using php4
> and trying to put together some code to update a db but I am not having
> much luck. This is the code I have come up with so far.
>
> <?php
>
> if (isset($_POST['submitted'])) { // if the form has been submitted
> handle it
>
> // check the required form fields.
> if (!empty($_POST['JobNumber'])) {
>
> // Include MYSQL info
> require_once
> '/home/e-smith/files/ibays/mct/cgi-bin/mysql_connect.inc.php';
>
> // Create the query
> $q = "INSERT INTO MyDB (JobNumber) VALUES ('{$_POST['JobNumber']}')";
>
> // Execute the query
> $r = mysql_query ($dbc, $q);
>
> //print a message indicating success
> if (mysql_affected_rows($dbc) == 1) {
> echo '<b><font color="green">It Has Been entered!</font></b>';
> } else {
> echo '<b><font color="red">Sorry it has failed!</font></b>';
> }
>
> Close the connection
> mysql_close($dbc)
>
> } else { //print a message if they failed to enter a catagory
> echo '<b><font color="red">You forgot to enter a value</font></b>';
> }
>
> } else {
> ?>
>
> Add a new category to the Job Number:<br />
> <form action="add_expense_category.php" method="post">
> <input type="text" name="JobNumber" size="30" maxlength="30" /><br />
> <input type="hidden" name="submitted" value="true" />
> <input type="submit" name="submit" value="Submit!" />
> </form>
>
> <?php
> }
> ?>
>
> but for some reason it doesn't work. Am I missing something I have
> looked over it 100 times but everything seems fine. Can anyone help me
> out.
>
> Thanks in advance
> Paul
>
Is it the whole code? I can't see where you connect to database
(mysql_connect(), mysql_select_database()).
Anyway try to be more precise. What is the real problem?
There is nothing in $_POST after submit or database returns an error?
If there is database error then what it is? Try putting
error_reporting(E_ALL) in the beginning of your script it could help
to diagnose your problem.
greetz Emil
[Back to original message]
|