Jump to content

kankaro

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kankaro's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thnx all of you guys it now clear in my mind i follow all of your instruction and it works great pretty smooth. .. yup im using an InnoDB engine in my table and my MySQL is version 5.0.45 and PHP version 5.2.4
  2. i just created the table with two foreign keys it seems it has a trouble.
  3. I supposed to make a web based inventory system, i have a table name products and other table name brand. wat i want is its just a one query in the brand table, when i update or delete some data in the brand table the data in the product table will be deleted also based on the foriegn key in the product table.
  4. hello guys is it possible to have 2 or more foreign key in one table which is that table has a relationship to another table.
  5. i tried it and it makes work great. that "null" there means that hes/her primary key in the database is auto incremented the "null" and '' are d same there's nothing wrong with it. also that connecting.php there i assume that chaddsuk has know it. This is the contents of that connecting.php <?php DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_NAME', 'database name'); //Connect to MySQL and select the database: $dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die ('Dili ma Connect sa MySQL! sayop ang bangag:' . mysql_error()); mysql_select_db(DB_NAME); ?> and also it will say process failed if during the process it will counter an error. also it's not necessary to put a single quote in $age becoz im sure that it is an integer type not a varchar. it will cause error during the process if you put it. A variable that is assigned as a storage of the integer data inputed doesn't need to have a single quote on them except if it is a varchar type. why don't you try it. so that you can see. Try to insert an integer to the database having a single quote it will sure prompt an error.
  6. here it goes the whole code. I hope it will help you. <?php if(isset($_POST['submit'])){ $name = $_POST['name']; $age = $_POST['age']; include ('connect.php'); // this is where you connect to the database the connect.php contents the script to connect to the database. $myQuery = "INSERT INTO users VALUES (null, '$name', $age)"; $result = mysql_query($myQuery); if(mysql_affected_rows($dbc)>0){ echo "Successfully Added"; } else{ echo "Process failed. Error ecounter"; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table> <tr> <td>Name:</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Age:</td> <td><input type="text" name="age"></td> </tr> <tr> <td><input type="submit name="submit" value="Add"></td> <td><input type="reset" name="clear" value="Reset"></td> </tr> </table></form>
  7. <?php //Assign contents of form to variables $name = $_POST['name']; $age = $_POST['age']; ?> Replace the code above with this <?php if(isset($_POST['submit'])){ $name = $_POST['name']; $age = $_POST['age']; include ('connect.php'); // this is where you connect to the database the connect.php contents the script to connect to the database. $myQuery = "INSERT INTO users VALUES (null, '$name', $age)"; $result = mysql_query($myQuery); if(mysql_affected_rows($dbc)>0){ echo "Successfully Added"; } else{ echo "Process failed. Error ecounter"; } } ?> <center><form action="<?PHP ($_SERVER[DOCUMENT_SELF]) mysql_query ( "INSERT INTO users (name, age) VALUES ('$name','$age')"; ?>" method="post"> <input type="text" name="name" size="20" /> Name <input type="text" name="age" size="20" /> Age <input type="submit" value="Store in database" /><input type="reset" value="Reset fields" /> </form></center>[/color] and alse this one, you don't have to put query into a form it will drive you crazy. replace it with this one <?php echo $_SERVER['PHP_SELF']; ?> -- this will tell the browser to add to this page.. i hope it will help you.. please read books about MySQL and PHP and also read some online toturials. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table> <tr> <td>NAme:</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Age:</td> <td><input type="text" name="age"></td> </tr> <tr> <td><input type="submit name="submit" value="Add"></td> <td><input type="reset" name="clear" value="Reset"></td> </tr> </table></form>
  8. try this one <form> <form action = "<? <?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- --> </div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="64"> </td> <td width="33"> </td> <td width="86"><a href="#">order no.</a></td> <td width="63"><a href="#">date</a></td> <td width="240"><a href="#">customer name</a></td> <td width="172"><a href="#">e-mail</a></td> <td width="64" align="right"><a href="#">amount</a></td> <td width="23"> </td> <td width="138"><a href="#">shipping method</a></td> </tr> </table> </div> <div class="clr"> <!-- --> <table width="850" border="0" cellspacing="0" cellpadding="0"> <?php // let's get some data include('adminconnect.php'); $sql = mysql_query("SELECT OrderNo, Orderdate, Custname, Amount, Shippingmet FROM admin WHERE Orderdate = DATE_FORMAT(now(),'%y/%m/%d')"); while( $row = mysql_fetch_array($sql, MYSQL_ASSOC) ) { // loop through and display ?> <tr align="left"> <td width="33"> </td> <td><input type = "checkbox" name="checkbox" value="checked"></td> <td width="33"> </td> <td width="82"><a href="javascript:openWindow('popup_detail.html', 'NewWindow', 615, 600)" class="black"><?php echo $row['OrderNo'];?></a></td> <td width="61" align="center"><?php echo $row['Orderdate'];?></td> <td width="230" align="Left"><?php echo $row['Custname'];?></td> <td width="170" align="center"><?php echo $row['Trackno'];?></td> <td width="56" align="right"><?php echo $row['Amount'];?></td> <td width="21"> </td> <td width="136" align="center"><?php echo $row['Shippingmet'];?></td> </tr> <? } ?> </table> <!-- data finish --> <!-- --> </div> <div id="btn"> <div id="btnL"><img src="../Admin_files/btn_delete.gif" alt="delete" width="73" height="23" /></div> <div id="btnSpace"> <!-- --> <input type="submit" name="submit" value="Process"> </form>
  9. hello i'm a newbe also in php, but when i look at your code it' something hard to work on it. If yuo want your code to work smoohtly make a database on it. it will surely find what you want. insert those words in the database.
  10. hello guys can you help me with my code. There's something fishy that i don't understand. can you guys help me out to solve these. here's the scenario. i've created a php code that will simply automatically add an integer that is inputed to the form into the database including the summation of the integer. for example 1+2+3+4+5 = 15 my aim is those numbers 1 2 3 4 and 5 that i inputed in the form will be inserted to the database including the total of those numbers in just one click of submit button but it doesn't work. i tried another way, when im going to click submit i'll just get the total of the sum of all the number and pass it into another page which process to insert that data into the database but the result is still the same it wont insert to the database. this my database design. |--------------------------------------------------------------------------------------------------- | Field | Type | Null | Key | Default | Extra |--------------------------------------------------------------------------------------------------- |id_no | int(10) | NO | Pri | Null | auto_increment |full_name |varchar(25) | NO | | | |1st_grade |float(4,2) unsigned | NO | | | |2nd_grade |float(4,2) unsigned | NO | | | |3rd_grade |float(4,2) unsigned | NO | | | |4th_grade |float(4,2) unsigned | NO | | | |total |float(6,2) unsigned | NO | | | ---------------------------------------------------------------------------------------------------- I will show my code on how i do it. this is my code to get the total of the number that i inputed and pass it on another page. <?php $first_grade = 00; $second_grade = 00; $third_grade = 00; $fourth_grade = 00; $total_grade = 00; function calculate($first_grade,$second_grade,$third_grade,$fourth_grade) { global $first_grade,$second_grade,$third_grade,$fourth_grade; $total = (($first_grade+$second_grade)+($third_grade+$fourth_grade)); return $total; } $first_grade = isset($_POST['first_grade']) ? $_POST['first_grade'] : ''; $second_grade = isset($_POST['second_grade']) ? $_POST['second_grade'] : ''; $third_grade = isset($_POST['third_grade']) ? $_POST['third_grade'] : ''; $fourth_grade = isset($_POST['fourth_grade']) ? $_POST['fourth_grade'] : ''; $total_grade = isset($_POST['total_grade']) ? $_POST['total_grade'] : ''; if(empty($_POST['fullname'])){ $fullname=FALSE; $msg = "You need to fill-up the form"; } else { $fullname=$_POST['fullname']; } ?> <?php if((isset($_POST['submit']) && ($fullname != '') && ($first_grade != '') && ($first_grade != '') && ($first_grade != '') && ($first_grade != ''))) { ?> <?php $total_grade = abs(calculate($first_grade,$second_grade,$third_grade,$fourth_grade)); } else { echo "$msg"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table> <tr> <td>Name:</td> <td><input type="text" name="fullname" value="<?php echo $fullname; ?>" /></td> </tr> <tr> <td>First Grade:</td> <td><input type="text" name="first_grade" value="<?php echo $first_grade; ?>" /></td> </tr> <tr> <td>Second Grade:</td> <td><input type="text" name="second_grade" value="<?php echo $second_grade; ?>"/></td> </tr> <tr> <td>Third Grade:</td> <td><input type="text" name="third_grade" value="<?php echo $third_grade; ?>"/></td> </tr> <tr> <td>Fourth Grade:</td> <td><input type="text" name="fourth_grade" value="<?php echo $fourth_grade; ?>"/></td> </tr> <tr> <td>Total Grade:</td> <td><?php echo $total_grade; ?></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="submit"/></td> <?php echo "<td align=\"center\"><a href=\"addgrade.php?name=$fullname&first_grade=$first_grade&second_grade=$second_grade&third_grade=$third_grade&fourth_grade=$fourth_grade&total_grade=$total_grade\" target=\"_blank\">submit</a></td> </tr>"; ?> </table></form> And this is the code that will process for inserting my data to the database it will get the data that i pass and then process to insert in the database. <?php if(isset($_GET['add'])){ include('connect.php'); $query="INSERT INTO grade VALUES (null, '$_GET[name]', $_GET[first_grade], $_GET[second_grade], $_GET[third_grade], $_GET[fourth_grade], $_GET[total_grade])"; echo "$query"; $sqlResult=mysql_query($query); if(mysql_affected_rows($dbc)>0){ echo "Successfully Added"; } else{ echo "Process Failed, Error ecounter"; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"> <table> <tr> <td>Fullname:</td> <td><input type="text" name="name" value="<?php echo "$_GET[name]"; ?>" /></td> </tr> <tr> <td>First Grade:</td> <td><input type="text" name="first_grade" value="<?php echo "$_GET[first_grade]"; ?> " /></td> </tr> <tr> <td>Second Grade:</td> <td><input type="text" name="second_grade" value="<?php echo "$_GET[second_grade]"; ?>"/></td> </tr> <tr> <td>Third Grade:</td> <td><input type="text" name="third_grade" value="<?php echo "$_GET[third_grade]"; ?>"/></td> </tr> <tr> <td>Fourth Grade:</td> <td><input type="text" name="fourth_grade" value="<?php echo "$_GET[fourth_grade]"; ?>"/></td> </tr> <tr> <td>Total Grade:</td> <td><input type="text" name="total_grade" value="<?php echo "$_GET[total_grade]"; ?>"/></td> </tr> <tr> <td align="center"><input type="submit" name="add" value="Add"/></td> </tr> </table></form>
  11. thnx to you cooldude832 thnx for the help... now my code works better.... thnx guys... <?php include 'connect.php'; $result="SELECT id, name FROM try"; $r=mysql_query($result); echo" <table>"; while($row=mysql_fetch_array($r, MYSQL_ASSOC)){ echo "<tr><td><a href=\"tryedit.php?name={$row['name']}&id={$row['id']}\">{$row['name']}</a></td><td> {$row['id']}</tr>"; } echo "</table>"; mysql_close($dbc); ?>
  12. hello every one im lyndon these is my first time to be here in this furom. Im a newbie in PHP Programming i need your help guys regarding my PHP code. the purpose of this is to pass a value of my query data to the field id in order for me to edit that data into another link. please help me guys. when i execute it i've got an error saying that: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Webserver\Apache2\Apache2.2\htdocs\test.php on line 13 i am using a PHP 5.2.4 version, Apache 2.2.4 version and MySQL 5.0.45 version. this is a binary configuration set up of my server.. please help me guys.. <?php include 'connect.php'; $result="SELECT * FROM try"; $r=mysql_query($result); echo" <table>"; while($row=mysql_fetch_array($r, MYSQL_ASSOC)){ echo "<tr><td><a href=\"http://edit.php?id=$row['id']\">".$row['id']."</a></td><td><a href=\"http://edit.php?id=$row['name']\">".$row['name']."</td></tr>"; } echo "</table>"; mysql_close($dbc); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.