Jump to content

ali_b

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ali_b's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hey, i have a page on my website that has a drop down menu. it has towns in my area and i have a database that i can make display the data in it in a table on another page. what i want it to do is..... on the drop down menu if i click North berwick i want it to go to a page where it shows all the shops in north berwick which are in the database.. and if i click on gullane it would show all the shops in gullane and so on. Could you please help me on how to do this, Thanks, Ali
  2. i worked out how to do it, problem solved
  3. if i insert to data using phpMyAdmin it is displayed so it is working lol just the insert page isnt
  4. cheers, ill give that a go, i think there is soming wrong with the database aswell. On php myadmin thing it has a warning that says "PRIMARY and INDEX keys should not both be set for column `id`" How do i fix that?
  5. ive tried this, <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO contacts VALUES(first,last,phone,mobile,fax,email,web) ('" . $first . "''" . $last . "','" . $phone . "','" . $mobile . "','" . $fax . "', '" . $email . "','" . $web . "',)"; mysql_query($query); mysql_close(); ?> but it still doesnt seem to work. any ideas?
  6. What do these bits do? "->" could i do $query = "INSERT INTO contacts VALUES (first, blah, blah) ('$first','$last','$phone','$mobile','$fax','$email','$web')"; would that work?
  7. Me agggain lol, trying another tutorial that i cant get to work Its a tutorial where u insert data into a database and display it but with some extra features such as linking to a website. the problem with it is that when i insert data i think it is inserted but when i go to the index page a new row is created but none of the info is displayed Maybe you could look through the code below and see if anything is wrong with it. i feel this is the best way for me to learn. Here how i connect to the database: <? $username="name"; $password="pw"; $database="db"; ?> Here is how i add info to the database: <form action="insert.php" method="post"> First Name: <input type="text" name="first"><br> Last Name: <input type="text" name="last"><br> Phone: <input type="text" name="phone"><br> Mobile: <input type="text" name="mobile"><br> Fax: <input type="text" name="fax"><br> E-mail: <input type="text" name="email"><br> Web: <input type="text" name="web"><br> <input type="Submit"> </form> Here is the php that adds it to the db: <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query); mysql_close(); ?> and here is where it should be displayed: <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> </tr> <? ++$i; } echo "</table>"; ?> Thank you very much for your help, its much appriciated ;D Ali
  8. i sorta get it, ill give it a go now
  9. im not very familur to the php?id=$id stuff. how does this work? i dont understand how i can link it to the page about the restraunt.... normally if the restraunt info page was called rest1 the link would be <a href="rest1.html"></a> so what would i call the page about the restraunt :S:S:S loooool i dont think i could have explained that any worse but hopefully u get me Cheers
  10. Hello, I have managed to insert data into a database and display it in a table. i just did a very basic example to see if it would work. so what i get is this: ID Name Age 1 Ali 17 2 blah 20 to insert the data i used this : <html> <head> <title>Forms</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action="insert.php"> <p>Name:-<br> <input name="name" type="text" id="name"> <br> <br> Age:-<br> <input name="age" type="text" id="age"> <br> <br> <input type="submit" name="Submit"> </p> </form> </body> </html> to display it in a table i used this: <?php $mysqlLink = mysql_connect( 'localhost' , 'name' , 'pw' ); mysql_select_db( 'menugenc_clients' , $mysqlLink ); $table = 'test'; if( $result = mysql_query('SELECT * FROM ' . $table ) ) { echo '<table border="1">'; $fieldCount = mysql_num_fields( $result ); echo "<tr>"; for( $i = 0; $i < $fieldCount; $i++ ) { echo '<td><strong>' . mysql_field_name( $result, $i ) . '</strong></td>'; } echo "</tr>"; if( mysql_num_rows( $result ) ) { while( $row = mysql_fetch_row( $result ) ) { echo '<tr>'; for( $i = 0; $i < $fieldCount; $i++ ) { echo '<td>' . $row[$i] . '</td>'; } echo '</tr>'; } } else { echo '<tr><td colspan="' . $fieldCount . '">No rows selected...</td></tr>'; } echo '</table>'; } else { echo 'Query Error: ' . mysql_error( ); } mysql_close( $mysqlLink ); ?> What i want to real one to look like is this: ID Name delivery 1 name of restraunt [picture of a wee van] but the "name of the restraunt" bit will be a link to another page with info about the restraunt. and if it can deliver there will be a picture of a van and if it can there will be a picture of a van with a cross through it. The most important bit is the link bit. could you please tell me how to do this? Cheers very much ali.
  11. no actually it is sorted thanks very much
  12. hmm still doesnt work is there anything wrong on the index page?
  13. hi, This is my first time trying to do this so dont laugh . i found a tutorial how to insert select and view data from a database but i cant get it to work, it says that the data has been insterted but when i go to index.php nothing is shown, maybe it is my database? wht should the code be to make a suitable database? Here is the config.php to connect to the database <? $dbh=mysql_connect ("localhost", "<my username>", "<my password>") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("menugenc_clients"); ?> Here is the forms.php where i insert the data: <html> <head> <title>Forms</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action="insert.php"> <p>Name:-<br> <input name="name" type="text" id="name"> <br> <br> Age:-<br> <input name="age" type="text" id="age"> <br> <br> <input type="submit" name="Submit"> </p> </form> </body> </html> this then gets linked to insert.php <?php // Include the Mysql Connecting file (config.php) include "config.php"; // corrected by army, there was no ";" at the end, so the INCLUDE-function was not closed, and you got an error f you tried to run it. Now it is fixed and woks well. $name = $_POST['name']; $age = $_POST['age']; //Insert into Mysql Database: mysql_query("INSERT INTO test (name,age) VALUES( " . $name . ", " . $age . ")"); // Show a alert when data inserted to Mysql. echo "<script language=javascript>alert('Data inserted to Mysql Databse!'); window.location = 'forms.php'; </script>"; ?> it then says that my data has been inserted and i go to index.php which is this: <?php // Include Mysql Connecting file (config.php) include "config.php"; // Selecting data from Database: // Tip: Asteric (*) is used to select all the rows in the table name. $result = mysql_query("SELECT * FROM test"); while ($show = mysql_fetch_array($result)) { // Write the Name and Age inserted into Mysql Database echo "Name: " . $show['name']; echo "Age: " . $show['age']; } ?> but it is just a blank page can you see what is wrong with it? Cheers in advance, Ali
  14. i dont actually have any code yet. i dont know how to do it so i was asking for some tutorial that you might know of to get me started. sorry didnt really make myself clear :-\ cheers
×
×
  • 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.